<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  <h4 class="modal-title">常用菜单</h4>
</div>
<div class="modal-body">
  <div class="list-group" style="text-align: center;">
    <table width="80%" id="menuTable">
      <%firstMenus.forEach(function(firstMenu){%>
      <tr>
        <td width="20%" align="left"><strong><%=firstMenu.name%></strong></td>
        <td width="80%" align="left">

        </td>
      </tr>
      <% if(secondMenus[firstMenu.path]){ secondMenus[firstMenu.path].forEach(function(secondMenu){ %>
      <tr>
        <td width="20%" align="left" style="padding-left: 20px;"><%=secondMenu.name%></td>
        <td width="80%" align="left">
          <% if(secondMenus[secondMenu.path]){ secondMenus[secondMenu.path].forEach(function(thMenu){ %>
          <input type="checkbox" value="<%=thMenu.id%>" onclick="chk()" <%if(customMenus.indexOf(''+thMenu.id)>-1){%>checked<%}%>><%=thMenu.name%>
      <%});}%>
        </td>
      </tr>
      <%});}%>
      <%});%>
      </table>
    </div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
  <button type="button" id="okCustom" class="btn btn-primary">确 认</button>
</div>
<script type="text/javascript">
  function chk(){
    var ids=[];
    $("#menuTable").find("input[type=checkbox]").each(function(){
      if($(this).prop("checked")){
        ids.push($(this).val());
      }
    });
    if(ids.length>5){
      Toast.error("最多可选择5个菜单");
      return ids;
    }
    return ids;
  }
  $(function () {
    $("#okCustom").on("click",function(){
      var ids =chk();
      if (ids.length<6) {
        $.post("/private/sys/user/customDo", {ids: ids}, function (data) {
          if (data.code == 0) {
            $('#homeDetail').modal('hide');
            Toast.success(data.msg);
          } else {
            Toast.error(data.msg);
          }
        }, "json");
      }
    });
  });
</script>
